package com.edu.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.entity.User;
import com.edu.service.UserBackgroundService;
import com.edu.service.impl.UserBackgroundServiceImpl;

/**
 * Servlet implementation class addUserServlet
 */
@WebServlet("/addUserServlet")
public class addUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String username = request.getParameter("userName");
		String userpass = request.getParameter("userPass");
		String getPhone = request.getParameter("phone");
		String getState = request.getParameter("state");
		String position = request.getParameter("position");
	
		long phone = Long.parseLong(getPhone);

		int	state = Integer.parseInt(getState);
		System.out.println(phone);
		UserBackgroundService userBackService = new UserBackgroundServiceImpl();
		User user = new User(phone, username,userpass,phone,position,state);
		userBackService.addUser(user);
		request.getRequestDispatcher("FenYeUserServlet").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
